import React, { Component } from 'react'
import {Menu,Icon} from 'antd';
import {Link} from 'dva/router';
import {connect} from 'dva';
export default 
@connect(state=>state.login)
class componentName extends Component {
  renderMenus = (resources)=>{
    return resources.map(item=>{
        if(item.children&&item.children.length>0){
            return (
                <Menu.SubMenu key={item.key} title={<span><Icon type={item.icon}/>{item.name}</span>}>
                   {this.renderMenus(item.children)}
                </Menu.SubMenu>
            )    
        }else{
            return (
                <Menu.Item key={item.key}>
                  <Link to={item.key}><Icon type={item.icon}/>{item.name}</Link>
                </Menu.Item>
            )
        }
    });
  }  
  render() {
    return (
      <Menu
         theme="dark"
         mode="inline"
         defaultSelectedKeys = {[this.props.location.pathname]}
         defaultOpenKeys = {["/admin"]}
      >
          {this.props.userInfo&&this.renderMenus(this.props.userInfo.resources)}
      </Menu>
    )
  }
}
